package com.atguigu.tingshu.user.factory;


import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.user.pattern.DeliveryStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class DeliveryStrategyFactory {

    @Autowired
    private Map<String, DeliveryStrategy> deliveryStrategyMap;

    public DeliveryStrategy getDeliveryStrategy(String itemType){

        log.info("类型为:{}",itemType);

        if (deliveryStrategyMap.containsKey(itemType)){

            return deliveryStrategyMap.get(itemType);
        }

        log.error("当前商品类型不知处处理");
        throw new GuiguException(500,"当前商品类型不知处处理");
    }
}
